<!DOCTYPE HTML>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>

<p id="paragraph">Line 1<br>Line 2</p>

<script>
test(function(t) {
    // Due to rounding we won't get identical bounds as getBoundingClientRect(),
    // so allow the test to pass if we're within 1 pixel.
    var epsilon = 1;

    var axParagraph = accessibilityController.accessibleElementById("paragraph");
    var axStaticText1 = axParagraph.childAtIndex(0);
    eval("var axTextBounds1 = " + axStaticText1.boundsForRange(0, 6));

    var paragraph = document.getElementById("paragraph");
    var range = new Range();
    range.setStart(paragraph.firstChild, 0);
    range.setEnd(paragraph.firstChild, 6);
    var rangeBounds = range.getBoundingClientRect();

    assert_approx_equals(axTextBounds1.x, rangeBounds.left, epsilon, "Line 1 left");
    assert_approx_equals(axTextBounds1.y, rangeBounds.top, epsilon, "Line 1 top");
    assert_approx_equals(axTextBounds1.width, rangeBounds.width, epsilon, "Line 1 width");
    assert_approx_equals(axTextBounds1.height, rangeBounds.height, epsilon, "Line 1 height");

    var axStaticText2 = axParagraph.childAtIndex(2);
    eval("var axTextBounds2 = " + axStaticText2.boundsForRange(0, 6));
    range.setStart(paragraph.lastChild, 0);
    range.setEnd(paragraph.lastChild, 6);
    rangeBounds = range.getBoundingClientRect();

    assert_approx_equals(axTextBounds2.x, rangeBounds.left, epsilon, "Line 2 left");
    assert_approx_equals(axTextBounds2.y, rangeBounds.top, epsilon, "Line 2 top");
    assert_approx_equals(axTextBounds2.width, rangeBounds.width, epsilon, "Line 2 width");
    assert_approx_equals(axTextBounds2.height, rangeBounds.height, epsilon, "Line 2 height");
}, "Check bounds of inline text boxes after line breaks");
</script>
